package app.v1.wdt.mapper;

import app.v1.wdt.domain.pojo.WdtSalesOrderDetails;
import app.v1.wdt.domain.vo.GroupByShopNoAndSpecNoVo;
import com.gitee.feizns.quickstart.mybatis.plus.QuickstartBaseMapper;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.time.LocalDate;
import java.util.List;

/**
 * mapper wdt销售订单细节
 * @author feizns
 * @since 2023/07/19
 */
@Mapper
public interface WdtSalesOrderDetailsMapper extends QuickstartBaseMapper<WdtSalesOrderDetails> {

    /**
     * 删除之前日期
     * @param date 日期
     */
    @Delete("DELETE FROM wdt_sales_order_details d WHERE DATE(d.create_time) < #{date}")
    void deleteCreateBeforeDate(@Param("date") LocalDate date);

    /**
     * 计算按订单数据量
     * @param orderNo 订单没有
     * @return long
     */
    @Select("SELECT COUNT(*) FROM wdt_sales_order_details WHERE order_no = #{orderNo}")
    long countingByOrderNo(@Param("orderNo") String orderNo);

    /**
     * 分组商店没有和规范和交付日期
     * @param createDate 创建日期
     * @param consignDate 交付日期
     * @return {@link List}<{@link GroupByShopNoAndSpecNoVo}>
     */
    List<GroupByShopNoAndSpecNoVo> groupingByShopNoAndSpecNoAndConsignDate(@Param("createDate") LocalDate createDate, @Param("consignDate") LocalDate consignDate);

    /**
     * 分组交付日期
     * @param consignDate 交付日期
     * @return {@link List}<{@link GroupByShopNoAndSpecNoVo}>
     */
    List<GroupByShopNoAndSpecNoVo> groupingByConsignDate(@Param("consignDate") LocalDate consignDate);

    /**
     * 分组交付日期
     * @param consignDate 交付日期
     * @return {@link List}<{@link GroupByShopNoAndSpecNoVo}>
     */
    List<GroupByShopNoAndSpecNoVo> groupingByConsignDateByShopNoAndWarehouseNo(@Param("consignDate") LocalDate consignDate, @Param("shopNo") String shopNo, @Param("warehouseNo") String warehouseNo);

    /**
     * 根据consign_time删除数据
     * @param date {@link LocalDate}
     * @return int
     */
    int deleteByConsignDate(@Param("date") LocalDate date);

}
